home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / driveso.cls < prev    next >
Text File  |  1997-06-14  |  1KB  |  57 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CDrivesO"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. '$ Uses DRIVE.CLS
  13.  
  14. Private drives As New Collection
  15.  
  16. Private Sub Class_Initialize()
  17.     Refresh
  18. End Sub
  19.  
  20. ' Argument handy for refreshing local and/or remote, but not floppies
  21. Public Sub Refresh(Optional iFirst As Integer = 1)
  22.     Dim i As Integer, af As Long, sRoot As String
  23.     Dim drive As CDrive
  24.     ' Remove old ones
  25.     Do While drives.Count > iFirst
  26.         drives.Remove iFirst
  27.     Loop
  28.     ' Insert new
  29.     af = GetLogicalDrives()
  30.     For i = iFirst To 26
  31.         If RShiftDWord(af, i - 1) And 1 Then
  32.             Set drive = New CDrive
  33.             drive.Root = i
  34.             drives.Add drive, drive.Root
  35.         End If
  36.     Next
  37. End Sub
  38.  
  39. ' NewEnum must have the procedure ID -4 in Procedure Attributes dialog
  40. Public Function NewEnum() As IEnumVARIANT
  41. Attribute NewEnum.VB_UserMemId = -4
  42.     Set NewEnum = drives.[_NewEnum]
  43. End Function
  44.  
  45. Public Property Get Count() As Integer
  46.     Count = drives.Count
  47. End Property
  48.  
  49. ' Default property
  50. Public Property Get Item(v As Variant) As CDrive
  51. Attribute Item.VB_UserMemId = 0
  52.     ' Return default (Nothing) if error
  53.     On Error Resume Next
  54.     Set Item = drives(v)
  55. End Property
  56.  
  57.